<?php 
include 'method/win.php';

if(isset($_POST['submit'])){
    login($_POST['username'], md5($_POST['password']));
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>
    <link rel="stylesheet" href="css/A-login.css">
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.css">
</head>
<body style="background-color:#4f5555" >
<form id="form1" class="well" method="post" action="" onsubmit="return fnLogin()">
    <h3>管理员登录</h3>
    <div class=" input-group input-group-md">
              <span class="input-group-addon" id="sizing-addon1"><i
                      class="glyphicon glyphicon-user" aria-hidden="true"></i></span><input
            id="userName" type="text" class="form-control" placeholder="用户名"
            aria-describedby="sizing-addon1" name="username"/>
    </div>
    <br/>

    <div class="input-group input-group-md">
        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
        <input type="password"
               id="password" class="form-control"
               placeholder="密码"
               aria-describedby="sizing-addon1" name="password"/>
    </div>


    <br/>
    <div class="input-group input-group-md ">
        <span class="input-group-addon"><i class="glyphicon glyphicon-barcode"></i></span>
        <input type="text" id="input1" class="captcha"  placeholder="请输入验证码"  aria-describedby="sizing-addon1">
        <input type="text" class="" placeholder="点击刷新" onclick="createCode()" readonly="readonly" id="checkCode">
    </div>
    <div id="error_box"><br></div>
    <button type="submit" name="submit" class="btn btn-success btn-block">登录</button>
</form>
<script>


    function fnLogin() {
        var userName = document.getElementById("userName");
        var password = document.getElementById("password");
        var inputCode = document.getElementById("input1").value;
        var oError = document.getElementById("error_box");
        var isError = true;
        if (userName.value.length > 20 || userName.value.length < 6) {
            oError.innerHTML = "用户名请输入6-20位字符";
            isError = false;
            return false;
        }
        if (password.value.length > 20 || password.value.length < 6) {
            oError.innerHTML = "密码请输入6-20位字符";
            isError = false;
            return false;
        }
        if (inputCode.length <= 0) {
                oError.innerHTML = "请输入验证码！";
                isError = false;
                return false;
            } else if (inputCode != code) {
                oError.innerHTML = "验证码错误！";
                isError = false;
                createCode();//刷新验证码
                return false;
            }
        return true;
    }


    //验证码
    var code; //在全局 定义验证码
    function createCode() {
        code = "";
        var codeLength = 4;//验证码的长度
        var checkCode = document.getElementById("checkCode");
        var selectChar = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
        //所有候选组成验证码的字符，当然也可以用中文的

        for (var i = 0; i < codeLength; i++) {
            var charIndex = Math.floor(Math.random() * 36);
            code += selectChar[charIndex];
        }
        //alert(code);
        if (checkCode) {
            // checkCode.className = "code";
            checkCode.value = code;
        }
    }

</script>

</body>
</html>